using System;
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;

namespace Gj
{
    public class BaseObject : CoreObject
    {
        private Entity entity;

        public BaseObject(Entity e)
        {
            entity = e;
        }

        public bool IsAuto()
        {
            return false;
        }

        public bool IsExist()
        {
            return true;
        }

        public int GetIndex()
        {
            return 0;
        }

        public object GetId()
        {
            return 0;
        }

        public Entity GetEntity()
        {
            return entity;
        }

        public string GetName()
        {
            throw new NotImplementedException();
        }

        public string GetKey()
        {
            throw new NotImplementedException();
        }

        public void Replace(Entity e)
        {
            entity = e;
        }

        public int GetBaseType()
        {
            return ObjectService.EntityManager.GetComponentData<UnknowData>(entity).type;
        }

        public float GetRadius()
        {
            return ObjectService.EntityManager.GetComponentData<UnknowData>(entity).radius;
        }

        public float GetHeight()
        {
            return ObjectService.EntityManager.GetComponentData<UnknowData>(entity).height;
        }

        public virtual Vector3 GetPosition()
        {
            return ObjectService.EntityManager.GetComponentData<LocalTransform>(entity).Position;
        }

        public virtual Quaternion GetRotation()
        {
            return ObjectService.EntityManager.GetComponentData<LocalTransform>(entity).Rotation;
        }

        public void SetPosition(Vector3 position)
        {
            ObjectService.EntityManager.AddComponentData(entity,
                new LocalTransform { Position = position, Rotation = GetRotation() });
        }

        public void SetRotation(Quaternion rotation)
        {
            ObjectService.EntityManager.AddComponentData(entity,
                new LocalTransform { Position = GetPosition(), Rotation = rotation });
        }

        public void UpdatePosition(Vector3 position)
        {
            ObjectService.EntityManager.AddComponentData(entity,
                new LocalTransform { Position = position, Rotation = GetRotation() });
        }

        public void UpdateRotation(Quaternion rotation)
        {
            ObjectService.EntityManager.AddComponentData(entity,
                new LocalTransform { Position = GetPosition(), Rotation = rotation });
        }
    }
}